/*
 * @Author: hmhvictory 1400628624@qq.com
 * @Date: 2025-07-24 16:18:37
 * @LastEditors: hmhvictory 1400628624@qq.com
 * @LastEditTime: 2025-07-24 16:18:50
 * @FilePath: \实训笔记\day09\RandomNumberProbability.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package day09;

import java.util.Random;
public class RandomNumberProbability {
    public static void main(String[] args) {
        // 创建一个数组来存储随机数
        int[] randomNumbers = new int[100];
        // 创建一个数组来统计每个数字出现的次数
        int[] countArray = new int[7]; 
        // 生成100个[1,6]之间的随机数
        Random random = new Random();
        for (int i = 0; i < 100; i++) {
            // 生成1到6之间的随机数
            randomNumbers[i] = random.nextInt(6) + 1; 
            // 对应数字的计数加1
            countArray[randomNumbers[i]]++; 
        }
        // 输出每个数字出现的概率
        for (int i = 1; i <= 6; i++) {
            double probability = (double) countArray[i] / 100;
            System.out.println("数字 " + i + " 出现的概率是: " + probability);
        }
    }
}
